/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.pd.projectbuilder;

import cz.pd.projectbuilder.beans.load.ProjectBean;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 *
 * @author forrest
 */
public class Davka {

  private List<ProjectBean> davky = new ArrayList<ProjectBean>();

  public void addDavkaItem(ProjectBean projectBean) {
    davky.add(projectBean);
  }

  public void removeDavkaItem(ProjectBean projectBean) {
    davky.remove(projectBean);
  }

  public List<ProjectBean> getDavky() {
    return davky;
  }

  public void moveUp(int oldIndex) {
    if ((oldIndex - 1) >= 0) {
      Collections.swap(davky, oldIndex, oldIndex - 1);
    }
  }

  public void moveDown(int oldIndex) {
    if ((oldIndex + 1) < davky.size()) {
      Collections.swap(davky, oldIndex, oldIndex + 1);
    }
  }

  public void moveTop(int oldIndex) {
    if ((oldIndex - 1) >= 0) {
      Collections.rotate(davky.subList(0, oldIndex + 1), 1);
    }
  }

  public void moveBottom(int oldIndex) {
    if ((oldIndex + 1) < davky.size()) {
      Collections.rotate(davky.subList(oldIndex, davky.size()), -1);
    }
  }

  public void moveUp(ProjectBean davkaItem) {
    moveUp(davky.indexOf(davkaItem));
  }

  public void moveDown(ProjectBean davkaItem) {
    moveDown(davky.indexOf(davkaItem));
  }

  public void moveTop(ProjectBean davkaItem) {
    moveTop(davky.indexOf(davkaItem));
  }

  public void moveBottom(ProjectBean davkaItem) {
    moveBottom(davky.indexOf(davkaItem));
  }
}
